package momo.app.structure;

import junit.framework.TestCase;

public class SimpleCircularListTest extends TestCase
{
	private SimpleCircularList<String> list;
	private int capacity;
	
	protected void setUp() throws Exception {
		super.setUp();
		capacity = 5;
		list = new SimpleCircularList<String>(capacity);
		for(int i=0; i<capacity; i++)
			list.add(""+i);
	}

	public void testAddE()
	{
		list.add("a");
		list.add("b");
		
		String actual = list.get(list.size()-1);
		assertEquals("b", actual);
		
		actual = list.get(list.size()-2);
		assertEquals("a", actual);
	}

	public void testClear() {
		list.clear();
		assertEquals(0, list.size());
	}

	public void testContains() {
		assertTrue(list.contains("0"));
		assertTrue(list.contains("1"));
		assertTrue(list.contains("2"));
		assertTrue(list.contains("3"));
		assertTrue(list.contains("4"));
		assertEquals(false, list.contains("a"));
	}

	public void testGet() {
		list.add("a");
		String actual = list.get(0);
		assertEquals("1", actual);
		
		list.add("b");
		actual = list.get(0);
		assertEquals("2", actual);
	}

	public void testIndexOf() {
		list.add("a");
		list.add("b");
		
		assertEquals(-1, list.indexOf("0"));
		assertEquals(-1, list.indexOf("1"));
		assertEquals(0, list.indexOf("2"));
		assertEquals(1, list.indexOf("3"));
		assertEquals(2, list.indexOf("4"));
		assertEquals(3, list.indexOf("a"));
		assertEquals(4, list.indexOf("b"));
		
	}

	public void testIsEmpty() {
		assertEquals(false, list.isEmpty());
		list.clear();
		assertEquals(true, list.isEmpty());
	}

	public void testRemoveObject() {
		assertTrue(list.remove("0"));
		assertTrue(list.remove("1"));
		assertTrue(list.remove("2"));
		assertTrue(list.remove("3"));
		assertTrue(list.remove("4"));
		
		assertEquals(true, list.isEmpty());
	}

	public void testRemoveInt() {
		list.add("a");
		list.add("b");
		
		assertEquals("4", list.remove(2));
		assertEquals(4, list.size());
		
		assertEquals("3", list.remove(1));
		assertEquals("b", list.remove(2));
		assertEquals("a", list.remove(1));
		assertEquals("2", list.remove(0));
	}

	public void testSet() {
		list.set(0, "a");
		list.set(1, "b");
		list.set(2, "c");
		list.set(3, "d");
		list.set(4, "e");
		
		assertEquals("a", list.get(0));
		assertEquals("b", list.get(1));
		assertEquals("c", list.get(2));
		assertEquals("d", list.get(3));
		assertEquals("e", list.get(4));
	}

	public void testSize() {
		assertEquals(5, list.size());
		
		list.remove(2);
		assertEquals(4, list.size());
	}

}
